<?php

namespace Yolo\Logs;

use ReflectionException;
use Yolo\ComponentManager\AbstractComponent;
use Yolo\Di\DI;
use Yolo\Di\Errors\CircularDependencyException;
use Yolo\Di\Errors\InvalidAttributeException;
use Yolo\Di\Errors\ParameterTypeEmptyException;
use Yolo\Service\ApplicationContainer;

/**
 * Log component
 */
class LogComponent extends AbstractComponent
{
    public function __construct(
        private readonly ApplicationContainer $container
    ){}

    /**
     * Register the component.
     * @return void
     * @throws ReflectionException
     * @throws CircularDependencyException
     * @throws ParameterTypeEmptyException|InvalidAttributeException
     */
    public function register(): void
    {
        // 设置日志驱动
        switch ($this->container->getConfig()->get('log.driver', 'console')) {
            case 'file':
                DI::bind(LogInterface::class, FileLog::class);
                break;
            default:
                DI::bind(LogInterface::class, ConsoleLog::class);
                break;
        }

        DI::use(Log::class);
    }
}
